load("../src/includes.js");
load("unittest.js");

if (!console) {
	var console = {};
	if (print) console.log = print;
	else console.log = function () {};
}

DataCenterConf = {
	racks: [{name: 'r1'}, {name: 'r2'}],
	switches: [
		{name: 'sw1', ports: 10, speed: 100}],
	hosts: [
		{name: 'host1', disk: 'disk1', connect: 'sw1', rack: 'r1', apps: ['namenode']},
		{name: 'host2', disk: 'disk1', connect: 'sw1', rack: 'r1', apps: ['datanode']},
		{name: 'host3', disk: 'disk1', connect: 'sw1', rack: 'r1', apps: ['datanode']},
		{name: 'host4', disk: 'disk1', connect: 'sw1', rack: 'r1', apps: ['hdfsclient']}],
	disks: [{name: 'disk1', capacity: 100e9, used: 4e9,
    	   accessTime: 1, readThput: 100, writeThput: 100, nDisks: 1}]
};

var TestClient = UnitTest.extend({
	testFileWrite: function () {
		var dc = new DataCenter();
		
		dc.load(DataCenterConf);
		var cl = dc.getApplication('host4', 'hdfsclient');
		
		// packetsize = 100, blocksize=100, rep=1, disk=(1s, 100b/s)
		PACKET_SIZE = 100;
		cl.setTimer(10).done(function () {
			var f = cl.openFile("a", "w", 200, 2);
			f.append(300);
			f.close();
		});
		
		
		dc.sim.simulate(100);
		dc.getHost('host2').disk.report(print);
		dc.getApplication('host1', 'namenode').report(print);
	}
});

new TestClient().run();